package com.premedsidekick;

import android.app.ExpandableListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;

public class Interview extends ExpandableListActivity {
	ExpandableListAdapter adapter;
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		adapter = new ExpandableListAdapter();
		setListAdapter(adapter);
		ExpandableListView lv = getExpandableListView();
		lv.setDivider(null);
		//Drawable icon = this.getResources().getDrawable(R.drawable.expander_group);
		lv.setGroupIndicator(null);
		
		WindowManager mWinMgr = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
		int displayWidth = mWinMgr.getDefaultDisplay().getWidth();
		
		//lv.setIndicatorBounds(GetDipsFromPixel(22), GetDipsFromPixel(22));

		


		 
	}
	//Convert pixel to dip 
	public int GetDipsFromPixel(float pixels)
	{
	        // Get the screen's density scale
	        final float scale = getResources().getDisplayMetrics().density;
	        // Convert the dps to pixels, based on density scale
	        return (int) (pixels * scale + 0.5f);
	}

	public class ExpandableListAdapter extends BaseExpandableListAdapter {
        // Sample data set.  children[i] contains the children (String[]) for groups[i].
        private String[] groups = getResources().getStringArray(R.array.interview_questions_headers);
        private String[] children = getResources().getStringArray(R.array.interview_suggestions_footers);
        private String[] groups_unexpanded = getResources().getStringArray(R.array.interview_questions_headers_unexpanded);
        LayoutInflater inflater = LayoutInflater.from(Interview.this);
        
        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            return 1;
        }
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            //if (convertView == null) {
            convertView = inflater.inflate(R.layout.interview_footer, null);
            	
            TextView textview = (TextView)convertView.findViewById(R.id.interview_footer_textview_1);
        	textview.setText(children[groupPosition]);
            return convertView;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
        	//if (convertView == null) {
        		if (!isExpanded) {
		        	convertView = inflater.inflate(R.layout.interview_header_not_expanded, null);
		            TextView textView = (TextView)convertView.findViewById(R.id.interview_header_textview_1);
		            textView.setText(groups_unexpanded[groupPosition]);
        		}
        		else {
        			convertView = inflater.inflate(R.layout.interview_header_expanded, null);
        			TextView textView = (TextView)convertView.findViewById(R.id.interview_header_textview_1);
        			textView.setText(groups[groupPosition]);
        		}
        		
        	//}
			
            return convertView;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }

    }
}
